package com.lucenly.spell.adapter

import android.content.Context
import android.graphics.Color
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.AbsoluteSizeSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lucenly.spell.R
import com.lucenly.spell.utils.DisplayUtil
import com.moregold.mvvmlib.ext.sp2px

class TypeItemAdapter:  RecyclerView.Adapter<TypeItemAdapter.ItemHolder>{
    var context: Context? = null
    var data:List<Int> = arrayListOf()
    constructor(data: List<Int>, context: Context){
        this.data = data
        this.context = context
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_type_spell, parent, false)
        return ItemHolder(view)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    class ItemHolder(view: View) : RecyclerView.ViewHolder(view) {
        val contentView = view.findViewById<LinearLayout>(R.id.itemView)
        val view = view.findViewById<View>(R.id.view)
        val tvMoney = view.findViewById<TextView>(R.id.tvMoney)
    }

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        val money = "16.00"
        val ssb = SpannableStringBuilder()
        ssb.append("￥$money")
        val end = ssb.length
        ssb.setSpan(AbsoluteSizeSpan(context!!.sp2px(18f)),1,end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE )
        holder.tvMoney.text = ssb
    }
}